package com.agent.action.mapper;

import com.agent.action.dataobject.PractiseCatalogDO;
import com.agent.action.dto.PractiseDTO;
import com.agent.action.entity.CatalogEntity;
import com.agent.action.entity.PractiseEntity;
import com.agent.action.vo.PractisesCatalogVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface PractiseMapper {
    /**
     * 将练习题目存入数据库
     * @param practiseDTO
     */
    @Insert("insert into practise(userId,practiseId,type,content,picture,options,answer) values(#{userId},#{practiseId},#{type},#{content},#{picture},#{options},#{answer})")
    public void insertPractise(PractiseDTO practiseDTO);

    /**
     * 将练习集存入数据库
     */
    @Insert("insert into practiseCatalog(practiseId,practiseName,userId) values(#{practiseId},#{practiseName},#{userId})")
    public int insertPractiseCatalog(CatalogEntity catalogEntity);

    @Select("select practiseId,practiseName from practiseCatalog where userId=#{userId}")
    public List<PractisesCatalogVO> getPractisesCatalog(String userId);

    @Select("select count(*) from practise where practiseId=#{practiseId}")
    public int getPractise(String practiseId);

    @Select("select * from practise where practiseId=#{practiseId}")
    public List<PractiseDTO> getPractises(String practiseId);

    @Select("select id from practise where practiseId= #{practiseId}")
    public List<Long> getIds(String practiseId);

    @Delete("delete from practise where id=#{id}")
    public boolean deleteById(Long id);

    @Update("update practise set type=#{type},content=#{content},picture=#{picture},options=#{options},answer=#{answer}  where id=#{id}")
    public boolean updatePractise(PractiseDTO practiseDTO);
}
